package unit7;

import java.sql.*;

public class t_student {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String ur1 = "jdbc:mysql://localhost:3306/1613580010";
        String name = "root";
        String password = "123";
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //建立连接
        Connection con = DriverManager.getConnection(ur1, name, password);

        Statement stmt=con.createStatement();
        //添加记录
        stmt.executeUpdate("insert into t_student values('1','蘑菇头','25')");
        stmt.executeUpdate("insert into t_student values('2','陈翔','27')");
        stmt.executeUpdate("insert into t_student values('3','韩梅梅','15')");
        stmt.executeUpdate("insert into t_student values('4','李雷','18')");
        stmt.executeUpdate("insert into t_student values('5','小明','7')");
        stmt.executeUpdate("insert into t_student values('6','小红','10')");
        //删除语句
        stmt.executeUpdate("delete from t_student where(id='1')");
        stmt.executeUpdate("delete from t_student where(id='2')");
        stmt.executeUpdate("delete from t_student where(id='3')");
        //修改语句
        stmt.executeUpdate("update t_student set name='小花'where id='5'");
        stmt.executeUpdate("update t_student set name='小猪'where id='6'");
        ResultSet r = stmt.executeQuery("select*from t_student");
        while (r.next()){
            System.out.println("学号"+r.getString("id")+
                               "姓名:"+r.getString("name"+
                               "年龄"+r.getString("age")));
        }
    }
}
